package com.jx.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.plaf.basic.BasicToolBarUI.DockingListener;

import com.jx.dao.FindFuncsDao;
import com.jx.daoimpl.FindFuncsDaoImpl;
import com.jx.model.Func;
import com.jx.service.FindFuncsService;
import com.jx.service.FindSomeFuncsService;
import com.jx.servicrimpl.FindFuncsServiceImpl;
import com.jx.servicrimpl.FindSomeFuncsServiceImpl;

import net.sf.json.JSONObject;
/**
 * 查询所有的功能
 * @author zzzzzzz
 *
 */
public class FindFuncsController extends HttpServlet{
	FindFuncsService ffs=new FindFuncsServiceImpl();
	FindSomeFuncsService fsfs=new FindSomeFuncsServiceImpl();

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		resp.setCharacterEncoding("utf8");
		//前端获取数据
		String fname=req.getParameter("searchname");
		//获取分页信息
		int page=Integer.parseInt(req.getParameter("page"));
		int pagesize=Integer.parseInt(req.getParameter("rows"));
		int start=(page-1)*pagesize;
		//json对象
		JSONObject json=new JSONObject();
		//判断搜索框是否为空，调用对应方法
		if(fname!=null){
			json=fsfs.findSomeFuncsService(fname,start,pagesize);
		}else{
			json=ffs.findFuncsService(start,pagesize);
		}
		//传回数据
		PrintWriter pw=resp.getWriter();
		pw.write(String.valueOf(json));
	}
}
